#############################################################
#
# libxml2
#
#############################################################
XML2_VERSION=2.6.29
XML2_SOURCE=libxml2-sources-$(XML2_VERSION).tar.gz
XML2_SITE=ftp://xmlsoft.org/libxml2
XML2_DIR=$(BUILD_DIR)/libxml2-$(XML2_VERSION)

$(DL_DIR)/$(XML2_SOURCE):
	$(WGET) -P $(DL_DIR) $(XML2_SITE)/$(XML2_SOURCE)

$(XML2_DIR)/.unpacked: $(DL_DIR)/$(XML2_SOURCE)
	gzip -d -c $(DL_DIR)/$(XML2_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	touch $@

$(XML2_DIR)/.configured: $(XML2_DIR)/.unpacked
	(cd $(XML2_DIR); \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS) -DNO_LARGEFILE_SOURCE" \
		PKG_CONFIG_PATH="$(STAGING_DIR)/lib/pkconfig:$(STAGING_DIR)/usr/lib/pkgconfig" PKG_CONFIG="$(STAGING_DIR)/usr/bin/pkg-config" PKG_CONFIG_SYSROOT=$(STAGING_DIR) \
		./configure \
		--target=$(GNU_TARGET_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--build=$(GNU_HOST_NAME) \
		--prefix=/usr \
		--enable-shared \
		$(DISABLE_NLS) \
		--enable-static \
		--enable-ipv6=no \
		--without-debugging \
		--without-python \
		--without-threads \
	);
	touch $@

$(XML2_DIR)/libxml2.so: $(XML2_DIR)/.configured
	$(MAKE) -C $(XML2_DIR)
	touch $@
	
$(STAGING_DIR)/usr/lib/libxml2.so: $(XML2_DIR)/libxml2.so
	$(MAKE) DESTDIR=$(STAGING_DIR) -C "$(XML2_DIR)" install
	$(SED) "s,^libdir=.*,libdir=\'$(STAGING_DIR)/usr/lib\',g" $(STAGING_DIR)/usr/lib/libxml2.la
	touch $@

$(TARGET_DIR)/usr/lib/libxml2.so: $(STAGING_DIR)/usr/lib/libxml2.so
	cp -dpf $(STAGING_DIR)/usr/lib/libxml2.so* $(TARGET_DIR)/usr/lib
	-$(STRIP) $(TARGET_DIR)/usr/lib/libxml2.so*
	touch $@

$(TARGET_DIR)/usr/lib/libxml2.a: $(STAGING_DIR)/usr/lib/libxml2.so
	mkdir -p $(TARGET_DIR)/usr/include/libxml
	cp -dpf $(STAGING_DIR)/include/*.h $(TARGET_DIR)/usr/include/libxml
	cp -dpf $(STAGING_DIR)/lib/libxml2.a $(TARGET_DIR)/usr/lib/
	rm -f $(TARGET_DIR)/lib/libxml2.so.$(XML2_VERSION)
	(cd $(TARGET_DIR)/usr/lib; ln -fs ../../lib/libxml2.so.$(XML2_VERSION) libxml2.so)
	touch -c $@

xml2-headers: $(TARGET_DIR)/usr/lib/libxml2.a

xml2: uclibc pkgconfig $(TARGET_DIR)/usr/lib/libxml2.so

xml2-source: $(DL_DIR)/$(XML2_SOURCE)

xml2-clean:
	rm -f $(TARGET_DIR)/lib/libxml2.so*
	-$(MAKE) -C $(XML2_DIR) clean

xml2-dirclean:
	rm -rf $(XML2_DIR)
#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_XML2)),y)
TARGETS+=xml2
endif
